package com.hzpd.hainan.module.zhuangti.adapter;

import android.app.Activity;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzpd.hainan.R;
import com.hzpd.hainan.model.zhuanti.ZhuanTiBean;

import java.util.List;

import static android.R.attr.width;

/**
 * Created by Administrator on 2017/8/9.
 */

public class ZhuanTiAdapter extends BaseMultiItemQuickAdapter<ZhuanTiBean,BaseViewHolder> {
    private Activity activity;
    int width;
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ZhuanTiAdapter(Activity activity,List<ZhuanTiBean> data) {
        super(data);
        this.activity=activity;
        addItemType(0, R.layout.item_zhuanti);
        width= activity.getWindowManager().getDefaultDisplay().getWidth()-20;
    }

    @Override
    protected void convert(BaseViewHolder helper, ZhuanTiBean item) {
        switch (helper.getItemViewType()){
            case 0:
                Glide.with(mContext).load(item.getImgs().get(0)).into((ImageView) helper.getView(R.id.iv_zhuanti));
                helper.addOnClickListener(R.id.iv_zhuanti);
                setImageLayoutParams((ImageView) helper.getView(R.id.iv_zhuanti));
                break;
        }
    }
    public void setImageLayoutParams(ImageView imageView){
        ViewGroup.LayoutParams params;
        params= (ViewGroup.LayoutParams) imageView.getLayoutParams();
//        params.width=width;

        params.height= (int) (width*0.45);
        imageView.setLayoutParams(params);
    }
}
